<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>列出 MySQL 数据库中的表</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-list-tables" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_list_tables</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_list_tables</span> &mdash; <span class="dc-title">列出 MySQL 数据库中的表</span></p>

   </div>
   <div class="refsect1 unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealsy" id="refsect1-function.mysql-list-tables-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealsy">
    <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="methodname"><strong>mysql_list_tables</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
     [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code></span>
    ] ) : <span class="type">resource</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>mysql_list_tables()</strong></span>
     接受一个数据库名并返回和
     <span class="function"><a href="mysql_query.html" class="function">mysql_query()</a></span>
     函数很相似的一个结果指针。用
     <span class="function"><a href="mysql_tablename.html" class="function">mysql_tablename()</a></span>
     函数来遍历此结果指针，或者任何使用结果表的函数，例如
     <span class="function"><a href="mysql_fetch_array.html" class="function">mysql_fetch_array()</a></span>。
    </p>
    <p class="para">
     <code class="parameter">database</code>
     参数是需要被取得其中的的表名的数据库名。如果失败
     <span class="function"><strong>mysql_list_tables()</strong></span> 返回 <strong><code>FALSE</code></strong>。
    </p>
    <p class="para">
     为向下兼容仍然可以使用本函数的别名
     <span class="function"><strong>mysql_listtables()</strong></span>，但反对这样做。
    </p>
    <p class="para">
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <span class="simpara">
       该函数已经被删除了，请不要再使用该函数。您可以用命令 SHOW TABLES FROM DATABASE 来实现该函数的功能。
      </span>
     </p></blockquote>
    </p>
    <p class="para">
     <div class="example" id="example-2159">
      <p><strong>Example #1 <span class="function"><strong>mysql_list_tables()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$dbname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'mysql_dbname'</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysql_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;connect&nbsp;to&nbsp;mysql'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_list_tables</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbname</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"DB&nbsp;Error,&nbsp;could&nbsp;not&nbsp;list&nbsp;tables\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">'MySQL&nbsp;Error:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Table:&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
    <p class="para">
    参见 <span class="function"><a href="mysql_list_dbs.html" class="function">mysql_list_dbs()</a></span> 和
    <span class="function"><a href="mysql_tablename.html" class="function">mysql_tablename()</a></span>。
    </p>
   </div>

  </div></div></div></body></html>